package undestiny.logindemo.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import undestiny.logindemo.dao.UserDao;
import undestiny.logindemo.dao.UserDaoImpl;
import undestiny.logindemo.entity.User;

import java.util.ArrayList;
import java.util.List;

@Service
public class UserServiceImpl implements UserService {

    @Autowired
    private UserDao userDao;

    @Override
    public User getUser(String username,String password){
        User user = userDao.getUserByUsernameAndPassword(username,password);
        if(user == null)throw  new RuntimeException();
        return user;
    }

    @Override
    public List<String> getUsernames(){
        return new ArrayList<>(userDao.getUsernameList());
    }
}
